import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import a014 from './a014';
export default async function a013(fd: IFeidaoAiBrowserComponent, args
	: { currentTarget: HTMLElement }) {
	// 排序
	const node = args.currentTarget;
	const sort = node.getAttribute('sort');
	const name = node.getAttribute('data-name');
	const nodes = fd.data.node.querySelectorAll<HTMLSpanElement>('[data-feidao-actions="click:a013"]');
	const asc = new Array();
	const desc = new Array();
	if (sort === 'z') {
		node.setAttribute('sort', 'd');
		const child = node.childNodes[0].childNodes[1] as HTMLIFrameElement;
		set_node_cls(child, 'icon-shang', true);
		set_node_cls(child, 'icon-xia', false);
		set_node_cls(child, 'icon-shangxia', false);
		asc.push(name);
		set(fd, 'asc', asc);
		set(fd, 'desc', []);

		await a014(fd);
	}
	if (sort === 'd') {
		node.setAttribute('sort', 'z');
		const child = node.childNodes[0].childNodes[1] as HTMLIFrameElement;
		set_node_cls(child, 'icon-xia', true);
		set_node_cls(child, 'icon-shang', false);
		set_node_cls(child, 'icon-shangxia', false);
		desc.push(name);
		set(fd, 'asc', []);
		set(fd, 'desc', desc);
		await a014(fd);
	}
	Array.from(nodes).map((v) => {
		const name1 = v.getAttribute('data-name');
		if (name1 !== name) {
			v.setAttribute('sort', 'z');
			const child = v.childNodes[0].childNodes[1] as HTMLIFrameElement;
			set_node_cls(child, 'icon-shangxia', true);
			set_node_cls(child, 'icon-shang', false);
			set_node_cls(child, 'icon-xia', false);
		}
	});
}
